<?php
define("THIS_PAGE", "users");

require_once($_SERVER["DOCUMENT_ROOT"] . "/../sys/libs/init.lib");
include($_SERVER["DOCUMENT_ROOT"] . "/../sys/includes/adminheader.php");

print "<div class=\"pagebody\">";

$SQL = "SELECT u.*, CONCAT(FirstName, ' ', Surname) AS Label, \n"
	 . "       ut.Title As UserType, c.BusinessName AS ClientName \n"
	 . "  FROM users u \n"
	 . "       JOIN usertype ut ON ut.id = u.UserTypeID \n"
	 . "       LEFT JOIN client_user cu ON cu.UserID = u.id \n"
	 . "       LEFT JOIN clients c ON c.id = cu.ClientID \n";

$users = $db->getarray($SQL);

$form = new formBuilder;
print "<table width=\"100%\" border=\"0\" cellspacing=\"0\">\n
		<tr>\n
			\t<th align=\"left\">UserName</th>\n
			\t<th align=\"left\">Client</th>\n
			\t<th align=\"left\">Name</th>\n
			\t<th align=\"left\">Email</th>\n
			\t<th align=\"left\">Type</th>\n
			\t<th align=\"right\">E X</th>\n
		</tr>\n";

$row1 = "#ffffff";
$row2 = "#9999ff";

$i = 0;
foreach ($users as $key => $user) {

	$bgcolor = ($i++ % 2) ? $row1 : $row2;

	print "<tr style=\"background-color:{$bgcolor};\">\n
			\t<td>{$user->UserName}</td>\n
			\t<td>{$user->ClientName}</td>\n
			\t<td>{$user->Label}</td>\n
			\t<td>{$user->Email}</td>\n
			\t<td>{$user->UserType}</td>\n
			\t<td align=\"right\">" . $form->checkbox(array("name" => "edituser", "value" => $user->id, "title" => "Edit " . $user->Label, "alt" => "Edit " . $user->Label)) . " " . $form->checkbox(array("name" => "deleteuser", "value" => $user->id, "title" => "Delete " . $user->Label, "alt" => "Delete " . $user->Label)) . "</td>
			</tr>\n";

}
?>
</table></form>
